﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using Cinemon;
using Cinemon.MySqlConnect;
public partial class Movie_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == true)
        {
            if (movieName.Text != "")
            {
                using (DatabaseManager manager = new DatabaseManager())
                {
                    List<MySqlParameter> param = new List<MySqlParameter> {
				new MySqlParameter("mname", movieName.Text),
				new MySqlParameter("showtime", yearDrop.SelectedItem.Text+":"+monthDrop.SelectedItem.Text+":"+daydrop.SelectedItem.Text),
				new MySqlParameter("license", LicenseDrop.SelectedValue),
				new MySqlParameter("poster", imageURL.Text)
			};

                    manager.ExecuteNonQuery("InsertMovie", param);
                }
                
            }
            Response.Redirect("view.aspx");
        }
        using (DatabaseManager manager = new DatabaseManager())
        {
            LicenseDrop.DataSource = manager.ExecuteQuery("GetAllLicenses");
            LicenseDrop.DataTextField = "Company";
            LicenseDrop.DataValueField = "License ID";
            LicenseDrop.DataBind();
        }
        for (int i = 1; i < 60; i++)
        {
            if (i < 10)
            {
                monthDrop.Items.Add("0"+i.ToString());
                daydrop.Items.Add("0" + i.ToString());
            }
            else
            {
                monthDrop.Items.Add(i.ToString());
                daydrop.Items.Add(i.ToString());
            }
            
        }
        for (int i = 0; i < 5; i++)
        {
            yearDrop.Items.Add("0" + i.ToString());
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("view.aspx");
    }
}